package com.cn.jx.manager.service.query.Impl;

import java.util.ArrayList;
import java.util.List;

import com.cn.jx.common.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.cn.jx.common.util.page.PageObj;
import com.cn.jx.manager.dao.JobRepository;
import com.cn.jx.manager.po.Job;
import com.cn.jx.manager.service.query.IJobServiceQry;

import com.jx.jpaQuery.QueryCondition;
import com.jx.util.ArrayUtil;
import com.jx.util.DateUtil;
import com.jx.util.MapObject;

/**
 * 
 * @author 姜旭
 * @version v1.11.20.2019
 * @since 
 * <p>创建时间：2019年12月1日
 * <p>功能描述：
 * <p>官方网站：management/admin/index
 * <p>邮箱地址：524577360@qq.com
 */
@Service("jobServiceQry") 
@Transactional
public class JobServiceImplQry extends BaseService implements IJobServiceQry {
	@Autowired
	private JobRepository jobDao;

	/* 分页查询 */
	@Override
	@Transactional(readOnly = true)
	public PageObj<MapObject> findJobByPageAndParams(QueryCondition cond) throws Exception {
		Specification<Job> speci = getSpecification(cond);
		Pageable pageable = getPageables(cond);
		Page<Job> puser = jobDao.findAll(speci, pageable);
		List<Job> list=puser.getContent();
		List<MapObject> listContent=new ArrayList<MapObject>();
		if(ArrayUtil.listNotEmpty(list)){
			list.forEach(j->{
				MapObject mp=MapObject.getInstance();
				mp.put("jobName", j.getJobName());
				mp.put("jobCode",j.getJobCode());
				mp.put("jobDescribe", j.getJobDescribe());
				mp.put("sort", j.getSort());
				mp.put("createTime", DateUtil.getDateFmt(j.getCreateTime()));
				mp.put("id", j.getId());
				listContent.add(mp);
			});
		}
		PageObj<MapObject> pageJob = new PageObj<MapObject>(puser,listContent);
		return pageJob;
	}

	/* 根据主键查下 */
	@Override
	@Transactional(readOnly = true)
//	@RedisCacheSave(key = "jobServiceQry", value = "'getJobById='.concat(#jobId)", rTime = RedisTime.SIX_HOURS, cls = Job.class)
	public Job getJobById(String jobId) {
		Job job = findEntityByPkid(jobId, Job.class);
		return job;
	}

	/* 查询所有job 提供给人员选择岗位上使用 */
	@Override
	@Transactional(readOnly = true)
//	@RedisCacheSave(key = "jobServiceQry", value = "'findAllJob'", rTime = RedisTime.SIX_HOURS, cls = Job.class)
	public List<Job> findAllJob() {
		return jobDao.findAllJob();
	}
}
